package com.highcom.service.impl;

import com.highcom.mapper.MemberDao;
import com.highcom.mapper.OrderDao;
import com.highcom.service.ReportService;
import com.highcom.utils.DateUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @version 1.0
 * @Author YangJiaQuan_hrbnu
 * @Date 2024/8/8 10:48
 */

@Service
public class ReportServiceImpl implements ReportService {

    @Resource
    private MemberDao memberDao;

    @Resource
    private OrderDao orderDao;
    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        //  报表日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //  本周一日期
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //  本月第一天日期
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        //  本日新增会员数
        Integer todayNewMember = memberDao.findMemberCountByDate(today);
        //  总会员数
        Integer totalMember = memberDao.findMemberTotalCount();
        //  本周新增会员数
        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(thisWeekMonday);
        //  本月新增会员数
        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(firstDay4ThisMonth);
        //  今日预约数
        Integer todayOrderNumber = orderDao.findOrderCountByDate(today);
        //  本周预约数
        Integer thisWeekOrderNumber = orderDao.findOrderCountAfterDate(thisWeekMonday);
        //  本月预约数
        Integer thisMonthOrderNumber = orderDao.findOrderCountAfterDate(firstDay4ThisMonth);
        //  今日到诊数
        Integer todayVisitsNumber = orderDao.findVisitsCountByDate(today);
        //  本周到诊数
        Integer thisWeekVisitsNumber = orderDao.findVisitsCountAfterDate(thisWeekMonday);
        //  本月到诊数
        Integer thisMonthVisitsNumber = orderDao.findVisitsCountAfterDate(firstDay4ThisMonth);

        List<Map> hotSetmeal = orderDao.findHotSetmeal();
        HashMap<String, Object> result = new HashMap<>();
        result.put("hotSetmeal",hotSetmeal);
        result.put("totalMember",totalMember);
        result.put("thisWeekNewMember",thisWeekNewMember);
        result.put("thisMonthNewMember",thisMonthNewMember);
        result.put("todayOrderNumber",todayOrderNumber);

        result.put("thisWeekOrderNumber",thisWeekOrderNumber);
        result.put("thisMonthOrderNumber",thisMonthOrderNumber);

        result.put("todayVisitsNumber",todayVisitsNumber);
        result.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        result.put("thisMonthVisitsNumber",thisMonthVisitsNumber);

        result.put("todayNewMember",todayNewMember);

        result.put("reportDate",today);
        return result;
    }
}
